﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Dynamic;

namespace ConsoleApp
{
    public delegate void CatListeningHandler();

    public class TestClass1
    {
        public event CatListeningHandler xx;
        public void Run()
        {
            //
            Console.WriteLine("xx");
        }
    }

    public class TestClass2
    {
        public TestClass2()
        {
            TestClass1 t1 = new TestClass1();
            t1.xx += new CatListeningHandler(t1.Run);
        }

        void t1_xx()
        {
            throw new NotImplementedException();
        }
    }

    public class Animal { }
    public class Cat : Animal { }
    public delegate Animal AniHandler(Animal arg);
    public class Test_Covariance
    {
        public static Animal AniMethod(Animal a) { return null; }
        public static Cat CatMethod(object o) { return null; }
        public Test_Covariance()
        {
            AniHandler handler1 = AniMethod;
            AniHandler handler2 = CatMethod;

            sbyte s3 = 2;
            byte s4 = 3;
            short s2 = 33;
            ushort s1 = 33;
            int s5 = 3;
            uint s6 = 3;
            long s7 = 3;
            ulong s8 = 3;


        }
    }

    class Class1
    {
        private int t1;
        protected int t2;
        public int t3;
        internal int t5;
        protected internal int t4;

        public Class1()
        {
            dynamic param1 = new System.Dynamic.ExpandoObject();
            param1.ABC = "ddd";
            param1.ID = 2;

            IEnumerable<object> objs = new List<string> { "t", "name" };

            List<string> obj1 = new List<string> { "uuu" };

        }

        public void ToDo1(int OptionalArg
            , string arg1 = "default arg1"
            , string arg2 = "default arg2")
        {
            Console.WriteLine("arg1={0},arg2={1}", arg1, arg2);
        }

        public void ToDo1(int arg1, string arg2)
        {
            ToDo1(OptionalArg: 1, arg1: "2", arg2: "3");
        }

        public void ToDo2(int a, string b)
        {
            //
        }

        public void Test_ToDo1()
        {
            ToDo1(1);
            ToDo1(1, "Arg1");
            ToDo1(1, "Arg2");
        }

    }

    public class TestClass
    {
        /// <summary>
        /// 冒泡排序。
        /// </summary>
        /// <param name="array"></param>
        public void BubbleSort(int[] array)
        {
            int length = array.Length;

            for (int i = 0; i <= length - 1; i++)
            {
                for (int j = length - 1; j > i; j--)
                {
                    if (array[j] < array[j - 1])
                    {
                        int temp = array[j];
                        array[j] = array[j - 1];
                        array[j - 1] = temp;
                    }
                }
            }

            for (int i = 0; i < array.Length; i++)
            {
                Console.WriteLine(array[i]);
            }

        }

        public void SelectOrder(int[] a)
        {
            for (int i = 0; i < a.Length - 1; i++)
            {
                int minIndex = i;

                for (int j = i + 1; j < a.Length; j++)
                {
                    if (a[j] < a[minIndex])
                    {
                        minIndex = j;
                    }
                }

                int temp = a[i];
                a[i] = a[minIndex];
                a[minIndex] = temp;


            }
            for (int i = 0; i < a.Length; i++)
            {
                Console.WriteLine(a[i]);
            }
        }

    }

}
